package org.mall.modules.cash.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.mall.common.constant.SellerCashStatusEnum;
import org.mall.modules.cash.entity.SellerCashInfo;
import org.mall.modules.cash.entity.SellerCashInfoVO;
import org.mall.modules.cash.mapper.SellerCashInfoMapper;
import org.mall.modules.cash.service.ISellerCashInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * @Description: 提现信息表
 * @Author: jeecg-boot
 * @Date: 2019-12-31
 * @Version: V1.0
 */
@Service
public class SellerCashInfoServiceImpl extends ServiceImpl<SellerCashInfoMapper, SellerCashInfo> implements ISellerCashInfoService {

    @Resource
    SellerCashInfoMapper cashInfoMapper;


    public Boolean updateStatusById(List<Long> collect, Integer value) {

        return cashInfoMapper.updateStatusByIds(collect, value);
    }

    @Override
    public Boolean updateStatusToWati(List<Long> collect) {
        Collection<SellerCashInfo> list = listByIds(collect);
        if (list.stream().anyMatch(o -> {
            return !o.getStatus().equals(SellerCashStatusEnum.WAIT_CASH.getValue());
        })) {
            return false;
        } else {
            return updateStatusById(collect, SellerCashStatusEnum.CASH_ING.getValue());
        }
    }

    @Override
    public Boolean updateStatusToFailure(List<Long> ids) {
        Collection<SellerCashInfo> list = listByIds(ids);
        if (list.stream().anyMatch(o -> {
            return !o.getStatus().equals(SellerCashStatusEnum.CASH_ING.getValue());
        })) {
            return false;
        } else {
            return updateStatusById(ids, SellerCashStatusEnum.CASH_FAILURE.getValue());
        }
    }
    @Override
    public Boolean updateStatusToSuccess(List<Long> ids) {
        Collection<SellerCashInfo> list = listByIds(ids);
        if (list.stream().anyMatch(o -> {
            return !o.getStatus().equals(SellerCashStatusEnum.CASH_ING.getValue());
        })) {
            return false;
        } else {
            return updateStatusById(ids, SellerCashStatusEnum.CASH_SUCCESS.getValue());
        }
    }

    @Override
    public List<SellerCashInfo> getSellerCashInfoLogListByShopIds(List<String> collect) {
        return  cashInfoMapper.getSellerCashInfoLogListByShopIds(collect);
    }

    @Override
    public List<SellerCashInfo> getSellerCashInfoLogListByShopIdsAndStatus(List<String> collect,Integer status) {
        return  cashInfoMapper.getSellerCashInfoLogListByShopIdsAndStatus(collect,status);
    }

    @Override
    public List<SellerCashInfoVO> getBySellerId(String id) {
        return cashInfoMapper.getBySellerId(id);
    }
}
